package com.geely.design.pattern.structural.proxy.dynamicproxy;

import com.geely.design.pattern.structural.proxy.IOrderService;
import com.geely.design.pattern.structural.proxy.OrderServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Test01 {
    public static void main(String[] args) {

        final OrderServiceImpl orderService = new OrderServiceImpl();
        orderService.saveOrder(null);

        System.out.println("=======================================");

        Class<? extends OrderServiceImpl> cls = orderService.getClass();
        Person a = (Person)Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[]{IOrderService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("之前...");
                Object obj = method.invoke(orderService, args);
                System.out.println("之后...");
                return obj;
            }
        });
        System.out.println(a);
        System.out.println(orderService);



    }
}
